package com.yeyks.order.dal.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;

import com.yeyks.common.constants.OrderStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author yun
 * @since 2019-12-03
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="OrderHead对象", description="订单表")
public class OrderHead implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @TableField("gmt_create")
    private Date gmtCreate;

    @TableField("gmt_modified")
    private Date gmtModified;

    @ApiModelProperty(value = "订单号")
    @TableField("order_no")
    private String orderNo;

    @ApiModelProperty(value = "对接方订单id")
    @TableField("source_order_id")
    private String sourceOrderId;

    @ApiModelProperty(value = "source_hotel_id")
    @TableField("source_hotel_id")
    private String sourceHotelId;

    @TableField("source_room_id")
    private String sourceRoomId;

    @ApiModelProperty(value = "yyks:平台   cn:龙腾 ")
    @TableField("source_type")
    private String sourceType;

    @ApiModelProperty(value = "资源方订单金额(分)")
    @TableField("source__amount")
    private Integer sourceAmount;

    @ApiModelProperty(value = "订单可取消最后时间")
    @TableField("last_cancel_time")
    private Date lastCancelTime;

    @ApiModelProperty(value = "对应的操作用户ID")
    @TableField("user_id")
    private Integer userId;

    @ApiModelProperty(value = "房间id")
    @TableField("room_id")
    private Integer roomId;

    @ApiModelProperty(value = "酒店ID")
    @TableField("hotel_id")
    private Integer hotelId;

    @ApiModelProperty(value = "下单时的酒店名称")
    @TableField("snapshot_hotel_name")
    private String snapshotHotelName;

    @ApiModelProperty(value = "订单当时房间名称")
    @TableField("snapshot_room_name")
    private String snapshotRoomName;

    @ApiModelProperty(value = "订单最终付款")
    @TableField("snapshot_total_fee")
    private Integer snapshotTotalFee;

    @ApiModelProperty(value = "订单最终退款金额")
    @TableField("snapshot_refund_fee")
    private Integer snapshotRefundFee;

    @ApiModelProperty(value = "退款理由")
    @TableField("refund_reason")
    private String refundReason;

    @ApiModelProperty(value = "优惠前合计(无优惠券总价)")
    @TableField("snapshot_origin_total_fee")
    private Integer snapshotOriginTotalFee;

    @ApiModelProperty(value = "状态，1待支付，2待入住，3已完成，4支付失败，5待退款，6已退款，7入住中，8已取消，9已评论，10待确认")
    @TableField("status")
    private Integer status;

    @ApiModelProperty(value = "入住时间")
    @TableField("check_in")
    private Date checkIn;

    @ApiModelProperty(value = "退房时间")
    @TableField("check_out")
    private Date checkOut;

    @ApiModelProperty(value = "入住天数")
    @TableField("days")
    private Integer days;

    @ApiModelProperty(value = "房间数")
    @TableField("room_count")
    private Integer roomCount;

    @ApiModelProperty(value = "用户券id")
    @TableField("user_coupon_id")
    private Integer userCouponId;

    @ApiModelProperty(value = "省份名")
    @TableField("province_name")
    private String provinceName;

    @ApiModelProperty(value = "城市名")
    @TableField("city_name")
    private String cityName;

    @ApiModelProperty(value = "入住人")
    @TableField("contact_name")
    private String contactName;

    @ApiModelProperty(value = "联系电话")
    @TableField("contact_phone")
    private String contactPhone;

    @ApiModelProperty(value = "支付方式，0微信app，1支付宝app，4小程序，5公众号，6wallet")
    @TableField("payment_method")
    private Integer paymentMethod;

    @ApiModelProperty(value = "用户评价分数0-100")
    @TableField("score")
    private Integer score;

    @ApiModelProperty(value = "平台抽成比例(万分比)")
    @TableField("yeyu_rate")
    private Integer yeyuRate;

    @ApiModelProperty(value = "vipflag为1代表vip订单利润(分润使用)：售价*折扣-拿房价，为3代表精选利润：售价*折扣-拿房价")
    @TableField("vip_profit")
    private Integer vipProfit;

    @ApiModelProperty(value = "删除标记：0；未删除  1：已删除")
    @TableField("delete_flag")
    private Integer deleteFlag;

    @ApiModelProperty(value = "省代理d")
    @TableField("province_agent_id")
    private Integer provinceAgentId;

    @ApiModelProperty(value = "市代id")
    @TableField("city_agent_id")
    private Integer cityAgentId;

    @ApiModelProperty(value = "区代理ID")
    @TableField("area_agent_id")
    private Integer areaAgentId;

    @ApiModelProperty(value = "订单类型逗号隔开，0 c2b，1vip，2b2c，3精选")
    @TableField("vip_flag")
    private Integer vipFlag;

    @ApiModelProperty(value = "会员卡号")
    @TableField("member_card_no")
    private String memberCardNo;

    @ApiModelProperty(value = "运营商/服务商/卡商ID")
    @TableField("saler_id")
    private Integer salerId;

    @ApiModelProperty(value = "0:运营商 1：服务商 2：卡商")
    @TableField("saler_type")
    private Integer salerType;

    @ApiModelProperty(value = "酒店佣金(分)")
    @TableField("fee_value")
    private Integer feeValue;

    @ApiModelProperty(value = "用户留言")
    @TableField("leave_message")
    private String leaveMessage;

    @ApiModelProperty(value = "备注")
    @TableField("remark")
    private String remark;

    @ApiModelProperty(value = "cn房态计划ID(用于支付校验)")
    @TableField("rateplan_id")
    private String rateplanId;

    @ApiModelProperty(value = "扩展信息{'roomImgUrls':[''],'hotelAddress':'hotelImgUrls':['']}")
    @TableField("extra_info")
    private String extraInfo;

    @ApiModelProperty(value = "开票信息id")
    @TableField("invoice_id")
    private Integer invoiceId;


    public static final String ID = "id";

    public static final String GMT_CREATE = "gmt_create";

    public static final String GMT_MODIFIED = "gmt_modified";

    public static final String ORDER_NO = "order_no";

    public static final String SOURCE_ORDER_ID = "source_order_id";

    public static final String SOURCE_HOTEL_ID = "source_hotel_id";

    public static final String SOURCE_ROOM_ID = "source_room_id";

    public static final String SOURCE_TYPE = "source_type";

    public static final String SOURCE__AMOUNT = "source__amount";

    public static final String LAST_CANCEL_TIME = "last_cancel_time";

    public static final String USER_ID = "user_id";

    public static final String ROOM_ID = "room_id";

    public static final String HOTEL_ID = "hotel_id";

    public static final String SNAPSHOT_HOTEL_NAME = "snapshot_hotel_name";

    public static final String SNAPSHOT_ROOM_NAME = "snapshot_room_name";

    public static final String SNAPSHOT_TOTAL_FEE = "snapshot_total_fee";

    public static final String SNAPSHOT_REFUND_FEE = "snapshot_refund_fee";

    public static final String REFUND_REASON = "refund_reason";

    public static final String SNAPSHOT_ORIGIN_TOTAL_FEE = "snapshot_origin_total_fee";

    public static final String STATUS = "status";

    public static final String CHECK_IN = "check_in";

    public static final String CHECK_OUT = "check_out";

    public static final String DAYS = "days";

    public static final String ROOM_COUNT = "room_count";

    public static final String USER_COUPON_ID = "user_coupon_id";

    public static final String PROVINCE_NAME = "province_name";

    public static final String CITY_NAME = "city_name";

    public static final String CONTACT_NAME = "contact_name";

    public static final String CONTACT_PHONE = "contact_phone";

    public static final String PAYMENT_METHOD = "payment_method";

    public static final String SCORE = "score";

    public static final String YEYU_RATE = "yeyu_rate";

    public static final String VIP_PROFIT = "vip_profit";

    public static final String DELETE_FLAG = "delete_flag";

    public static final String PROVINCE_AGENT_ID = "province_agent_id";

    public static final String CITY_AGENT_ID = "city_agent_id";

    public static final String AREA_AGENT_ID = "area_agent_id";

    public static final String VIP_FLAG = "vip_flag";

    public static final String MEMBER_CARD_NO = "member_card_no";

    public static final String SALER_ID = "saler_id";

    public static final String SALER_TYPE = "saler_type";

    public static final String FEE_VALUE = "fee_value";

    public static final String LEAVE_MESSAGE = "leave_message";

    public static final String REMARK = "remark";

    public static final String RATEPLAN_ID = "rateplan_id";

    public static final String EXTRA_INFO = "extra_info";

    public static final String INVOICE_ID = "invoice_id";

    /**
     * 根据订单的对象 拼接admin - App 首页的订单通知信息
     * @param orderHead 订单对象
     * @return 返回拼接字符串
     */
    public static String convertMessage(OrderHead orderHead) {
        StringBuilder context = new StringBuilder();
        //{"name":"钮一波","phone":"15888849709"}
        context.append("【").
                append(orderHead.getContactPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"))
                .append("】");
        if (orderHead.getStatus().equals(OrderStatus.preCheckIn) || orderHead.getStatus().equals(OrderStatus.living)) {
            context.append("预订了")
                    .append(orderHead.getSnapshotHotelName())
                    .append(orderHead.getSnapshotRoomName()).append(",");
            long time = orderHead.getCheckOut().getTime() - orderHead.getCheckIn().getTime();
            context.append(time / (24 * 60 * 60 * 1000)).append("晚！");
        } else if (orderHead.getStatus().equals(OrderStatus.preRefund)) {
            context.append("申请了退款，退款理由:");
            context.append(orderHead.getRefundReason());
            context.append(",请管理员登录web管理后端处理");
        }
        return context.toString();
    }

}
